package com.weixin1.dao;

import com.weixin1.bean.Manager;
import com.weixin1.utils.C3p0Utils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class ManagerDao {
    QueryRunner qr=new QueryRunner(C3p0Utils.comboPooledDataSource);
    //查询表中是否包含名字和密码一样的一条数据  返回一个manager类型
    public Manager getByManager(String name,String password){
        try {
            return qr.query("select m_id mId,m_name mName,m_password mPassword from manager " +
                    "where m_name=? and m_password=?",new BeanHandler<>(Manager.class),name,password);
        } catch (SQLException e) {
            throw  new RuntimeException();
        }
    }
    //修改密码
    public int update(String password,String name2,String password2) throws SQLException {
        return qr.update("update manager set m_password=? where m_name=? and m_password=?",
                password,name2,password2);
    }
}
